<link rel="stylesheet" href="/assets/libs/editormd/css/editormd.css"/>
<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <input type="hidden" id="at_id" value="{$model.abutment_id ?? ''}" required placeholder="请输入流转名称"
               autocomplete="off"
               class="layui-input">
        <input type="hidden" id="count_group_parent" value="{$group_parent_count ?? ''}" required placeholder="请输入流转名称"
               autocomplete="off"
               class="layui-input">
        <label class="layui-form-label">流转名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" value="{$model.title ?? ''}" required placeholder="请输入流转名称"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">对接部门</label>
        <div class="layui-input-block">
            <select name="abutment_group_id" lay-verify="required" lay-filter="abutment_group_id" lay-search="">
                <option value="">直接选择或搜索选择</option>
                {foreach $group as $key=>$vo}
                <option value="{$vo.id}" {if condition="($model.abutment_group_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item" id="abutmentId">
        <label class="layui-form-label">对接人</label>
        <div class="layui-input-block">
            <select name="abutment_id" id="abutment_id" lay-verify="required" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">流转周期</label>
        <div class="layui-input-block">
            <input type="text" name="period" id="period" value="{$model.period ?? ''}" required placeholder="请输入流转周期"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">流转描述</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" name="describe">{$model.describe ?? ''}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">流转物品</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" name="content">{$model.content ?? ''}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="开启" checked>
            <input type="radio" name="status" value="0" title="禁用">
        </div>
    </div>
    {if ( $group_parent_count == 0)}
    <div class="layui-form-item">
        <label class="layui-form-label">上级审核</label>
        <div class="layui-input-block">
            <input type="radio" name="is_superior" value="1" title="是"  disabled>
            <input type="radio" name="is_superior" value="0" title="否" checked disabled>
        </div>
        <span style="color: red;font-size: 12px;">备注:由于没有父级可选，该按钮禁用</span>
    </div>
    {else /}
    <div class="layui-form-item">
        <label class="layui-form-label">上级审核</label>
        <div class="layui-input-block">
            <input type="radio" name="is_superior" value="1" title="是" lay-filter="is_superior">
            <input type="radio" name="is_superior" value="0" title="否" checked lay-filter="is_superior">
        </div>
    </div>
    {/if}
    <div class="layui-form-item" id="superiorId">
        <label class="layui-form-label">上级列表</label>
        <div class="layui-input-block">
            <select name="superior_id" id="superior_id" lay-search="">
                <option value="">直接选择或搜索选择</option>
                {foreach $group_parent as $key=>$vo}
                <option value="{$vo.id}">{$vo.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-user-back-submit" id="LAY-user-back-submit" value="确认">
    </div>
</div>
<script src="/static/admin/video/jquery.js"></script>
<script src="/assets/libs/editormd/editormd.min.js"></script>
<script src="/static/admin/layui/layui.js"></script>

<script>
    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        treeTable: '../admin/lib/extend/authtree'
    }).use(['index', 'form', 'laydate'], function () {
        var $ = layui.$, form = layui.form, laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#period'
            , range: '~'
            , trigger: 'click'//呼出事件改成click
        });
        var select_val = $("select[name='abutment_group_id'] option:selected").val();
        if (select_val) {
            select_data(select_val);
        }
        form.on('select(abutment_group_id)', function (data) {
            select_data(data.value);
            $('#abutment_id').empty();
        });

        function select_data(id) {
            $.ajax({
                url: "{:url('wander/form_select')}",
                data: {'id': id},
                type: 'post',
                dataType: "json",
                async: true,
                success: function (res) {
                    $('#abutment_id').append(new Option("", 0));// 下拉菜单里添加元素
                    $.each($.parseJSON(res), function (index, item) {
                        $('#abutment_id').append(new Option(item.nickname, item.id));// 下拉菜单里添加元素
                    });
                    if ($('#at_id').val() != "") {
                        $("select[name='abutment_id']").find("option[value='" + $('#at_id').val() + "']").attr("selected", true);
                    }
                    form.render('select');
                }
            });
        }

        $('#superiorId').hide();
        form.on('radio(is_superior)', function (data) {
            if (data.value == 0) {
                $('#superiorId').hide();
            } else {
                $('#superiorId').show();
            }

        });

    });

</script>